package com.edu.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 统一字符集
 * 描述：
 * 创建人：飘
 * 创建时间：2024/10/30
 **/
@WebFilter("/*")
public class SetCharFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException { }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
                         FilterChain filterChain) throws IOException, ServletException {
        //设置请求对象的的字符编码
        servletRequest.setCharacterEncoding("utf-8");
        //设置响应对象的的内容编码
        servletResponse.setContentType("text/html;charset=utf-8");
        //设置响应对象的的字符编码
        servletResponse.setCharacterEncoding("utf-8");
        //放行
        filterChain.doFilter(servletRequest, servletResponse);
    }
    @Override
    public void destroy() { }
}
